package com.currency.interceptor;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class ParamInterceptor implements HandlerInterceptor {
    private static final Log log = LogFactory.get(ParamInterceptor.class);

    //在请求处理之前进行调用（Controller方法调用之前
    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
//        StringBuffer url = httpServletRequest.getRequestURL();
//        BufferedReader br = null;
//        try {
//            br = new BufferedReader(new InputStreamReader(httpServletRequest.getInputStream(), "UTF-8"));
//        } catch (IOException e) {
//            log.warn(e.getMessage());
//        }
//        String line = null;
//        StringBuilder sb = new StringBuilder();
//        try {
//            while ((line = br.readLine()) != null) {
//                sb.append(line);
//            }
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        log.info("请求地址：{}, 请求参数：{}", url, sb.toString());
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
        //System.out.println("postHandle被调用");
    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
        //System.out.println("afterCompletion被调用");
    }
}
